import 'package:flutter/material.dart';

/*
  TextFieldWidget(controller: _personalName, labelText: 'sdfdas大萨达sfds'),
*/
class TextFieldWidget extends StatelessWidget {
  const TextFieldWidget(
      {Key key,
      this.controller,
      this.labelText,
      this.icon,
      this.callback,
      this.isObscure = false,
      this.mKey})
      : super(key: key);
  final TextEditingController controller;
  final String labelText;
  final String mKey;
  final Icon icon;
  final Function callback;
  final bool isObscure;

  @override
  Widget build(BuildContext context) {
    return PrimaryColorOverride(
      color: Color(0xFF442B2D),
      child: TextField(
        cursorColor: Colors.black12,
        controller: controller,
        obscureText: isObscure,
        onChanged: (val) {
          callback(val, mKey);
        },
        decoration: InputDecoration(
          enabledBorder: UnderlineInputBorder(
            borderSide: BorderSide(color: Colors.grey[200]),
          ),
          focusedBorder: UnderlineInputBorder(
            borderSide: BorderSide(color: Colors.black),
          ),
          labelText: labelText,
          prefixIcon: icon,
        ),
      ),
    );
  }
}

class PrimaryColorOverride extends StatelessWidget {
  const PrimaryColorOverride({Key key, this.color, this.child})
      : super(key: key);

  final Color color;
  final Widget child;

  @override
  Widget build(BuildContext context) {
    return Theme(
      child: child,
      data: Theme.of(context).copyWith(primaryColor: color),
    );
  }
}
